<template>
	<!-- 一级评论 -->
	<view class="comment-item" :class="{ 'second-level-comment': isSecond }" :key="commentData.id" @click="handlePress(commentData)">
		<view class="app-avatar avatar">
			<image :src="commentData.userVO.avatarUrl"></image>
		</view>
		<view class="comment-content">
			<view class="info">
				<view class="name">{{ commentData.userVO.nickname }}</view>
				<view class="desc">{{ commentData.userVO.signature ? commentData.userVO.signature : defaultSignature }}</view>
			</view>
			<view class="content"> 
                <image
                    v-if="commentData.url"
                    :src="commentData.url"
                    mode="scaleToFill"
                    @click.stop="handleViewImage(commentData.url)"
                />
                <view>{{ commentData.content }}</view>    
            </view>
			<view class="time">{{ commentData.createTime }}</view>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		commentData: {
			type: Object,
			default: () => ({})
		},
        // 是否为二级评论
        isSecond: {
            ype: Boolean,
            default: false
        }
	},
	data() {
		return {
			defaultSignature: '这个人很懒，什么都没有留下'
		};
	},
	methods: {
		handlePress(commentData) {
			this.$emit('press', commentData);
		},
        handleViewImage(url) {
            this.$emit('viewImage', url);
        }
	}
};
</script>

<style lang="scss">
.comment-item {
	display: flex;
	margin-top: 20rpx;
	padding-bottom: 20rpx;
	border-bottom: solid 1px #eee;

	&:active {
		background-color: #e9e9e9;
	}

	.avatar {
		width: 60rpx;
		height: 60rpx;
		min-width: 60rpx;
		max-width: 60rpx;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.comment-content {
		display: flex;
		flex-direction: column;
		font-size: $font-size-base;

		.info {
			display: flex;
			align-items: center;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			line-height: 1em;

			.name {
				font-size: $font-size-small;
				color: #333;
				font-weight: bold;
				margin-right: 10rpx;
			}

			.desc {
				font-size: $font-size-small;
				color: #999;
			}
		}

		.content {
            display: flex;
            flex-direction: column;
            gap: 10rpx;
            word-break: break-all;
            word-wrap: break-word;
            line-height: 1.5em;
			margin: 0;
			margin-top: 5rpx;

            image {
                width: 200rpx;
                height: 200rpx;
                margin: 10rpx;
                border-radius: 8rpx;
            }
		}

		.time {
			font-size: $font-size-small;
			color: #999;
			margin-top: 5rpx;
		}
	}
}

.second-level-comment {
	padding-left: 60rpx;

	.avatar {
		width: 60rpx;
		height: 60rpx;
		min-width: 60rpx;
		max-width: 60rpx;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}
	}
}
</style>
